<template>
  <el-menu
    class="el-memu-demo"
    mode="horizontal"
    :default-active="activeIndex"
    :unique-opened="true"
  >
    <el-menu-item index="1">
      <router-link class="nav-link" :to="{name:'home'}">首页</router-link>
    </el-menu-item>

    <el-menu-item index="2">
      <router-link class="nav-link" :to="{name:'recipe'}">菜谱大全</router-link>
    </el-menu-item>
  </el-menu>
</template>

<script>
export default {
  name: "menus",
  data() {
    return {
      activeIndex: "1",
    };
  },
  watch: {
    $route: {
      handler() {
        this.activeIndex = this.$route.path === "/recipe" ? "2" : "1";
      },
    },
  },
};
</script>

<style>
.nav-link {
  display: inline-block;
}
</style>